package de.homelabs.bookstore.persistence;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import de.homelabs.spring.freemarker.domain.HLTemplateElement;

@Repository
public class TemplateElementDAO {

	private SessionFactory sessionFactory;
	
	private HibernateTemplate hibernateTemplate;
	
	@SuppressWarnings("unchecked")
	public List<HLTemplateElement> findTemplateElements(){
		//return sessionFactory.getCurrentSession().createSQLQuery("Select * from templateelement").list();
		//return (List<TemplateElement>) sessionFactory.getCurrentSession().createCriteria("from TemplateElement").list();
		return hibernateTemplate.find("from TemplateElement");
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
		hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
}
